// 属性管理API
import request from "@/utils/request";
import type { CategoryResponseData, AttrResponseData, Attr } from "./type";
// 接口地址
enum API {
  C1_URL = "/admin/product/getCategory1",
  C2_URL = "/admin/product/getCategory2/",
  C3_URL = "/admin/product/getCategory3/",
  // 获取分类下已有的属性接口
  ATTR_URL = "/admin/product/attrInfoList/",
  // 添加或修改属性的接口
  ADDORUPDATE_URL = "/admin/product/saveAttrInfo",
  // 删除属性的接口
  DELETE_URL = "/admin/product/deleteAttr/",
}

// 获取一级分类的接口方法
export const reqC1 = () => request.get<any, CategoryResponseData>(API.C1_URL);
// 获取二级分类的接口方法
export const reqC2 = (c1Id: number) =>
  request.get<any, CategoryResponseData>(API.C2_URL + c1Id);
// 获取三级分类的接口方法
export const reqC3 = (c2Id: number) =>
  request.get<any, CategoryResponseData>(API.C3_URL + c2Id);
// 获取分类下已有的属性的接口方法
export const reqAttr = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) =>
  request.get<any, AttrResponseData>(
    API.ATTR_URL + category1Id + "/" + category2Id + "/" + category3Id
  );

// 添加或修改属性的接口方法
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATE_URL, data);

// 删除属性的接口方法
export const reqDeleteAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETE_URL + attrId);
